﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CMSService
{
    /// <summary>
    /// 文章表
    /// </summary>
    public class DocService : ICMS.IDoc
    {
        DavidDB.ADO.DBManager db = null;
        private DocService()
        {
            db = new DavidDB.ADO.DBManager();
        }
        public DocService(DavidDB.ADO.DBManager db)
        {
            this.db = db;
        }



        /// <summary>
        /// 获取一个网站文章
        /// </summary>
        /// <param name="id">文章编号</param>
        /// <returns>网站文章，如果没有，返回Null</returns>
        public CMSModel.Doc GetModel(int id)
        {
            CMSModel.Doc returnValue = new CMSModel.Doc();
            returnValue.Id = id;
            returnValue = db.GetModel(returnValue);
            return returnValue;
        }
        /// <summary>
        /// 删除一个网站文章
        /// </summary>
        /// <param name="id">文章编号</param>
        /// <returns>成功删除，返回0，没有当前文章，返回-1</returns>
        public int Delete(int id)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            CMSModel.Doc model = new CMSModel.Doc();
            model.Id = id;
            db.Delete(model);
            return returnValue;
        }
        /// <summary>
        /// 增加一个网站文章
        /// </summary>
        /// <param name="announcement">网站文章实体</param>
        /// <returns>增加成功，返回0</returns>
        public int Insert(CMSModel.Doc doc)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            db.Insert(doc);
            return returnValue;
        }
        /// <summary>
        /// 编辑一个文章
        /// </summary>
        /// <param name="announcement">编辑完成的文章</param>
        /// <returns>编辑成功，返回0</returns>
        public int Edit(CMSModel.Doc doc)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            db.Edit(doc);
            return returnValue;
        }
        /// <summary>
        /// 到底最新的count条记录
        /// </summary>
        /// <param name="count">查询条数</param>
        /// <returns>如果记录足够多，返回count条，否则，返回所有记录</returns>
        public List<CMSModel.Doc> GetList(int count)
        {
            List<CMSModel.Doc> lists = new List<CMSModel.Doc>();
            var query = db.GetTopList(count, new CMSModel.Doc());
            foreach (CMSModel.Doc model in query)
            {
                lists.Add(model);
            }
            return lists;
        }

        /// <summary>
        /// 得到10条最新的记录
        /// </summary>
        /// <param name="column"></param>
        /// <returns></returns>
        public List<CMSModel.Doc> GetNewDocList(string column)
        {
            return null;
        }
    }
}
